from django.shortcuts import render, get_object_or_404
from django.views.generic import View

from blog.models import Post


class BlogHomeView(View):
    def get(self, request):
        all_posts = Post.objects.all()
        return_dic = {'all_posts': all_posts}
        return render(request, "index.html", return_dic)


class BlogDetailView(View):
    def get(self, request, post_id):
        post = get_object_or_404(Post, pk=post_id)
        # post = Post.objects.get(id=post_id)
        return_dic = {'post': post}
        return render(request, "post-detail.html", return_dic)